﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", ConfigFileExtension = "config", Watch = true)]
namespace FormsAuthWeb.Utils
{
    /// <summary>
    /// 日志记录类
    /// </summary>
    public class Logger
    {
        private static ILog logger = null;

        static Logger()
        {
            if (logger == null)
            {
                log4net.Config.XmlConfigurator.Configure();
                logger = LogManager.GetLogger("WebLogger");
            }
        }

        /// <summary>
        /// 将调试信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        public static void Debug(object message)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug(message);
            }
        }

        /// <summary>
        /// 将调试信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        /// <param name="exception">记录异常信息，包含用于描述调用堆栈的直接帧的字符串。</param>
        public static void Debug(object message, Exception exception)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug(message, exception);
            }
        }

        /// <summary>
        /// 将错误信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        public static void Error(object message)
        {
            if (logger.IsErrorEnabled)
            {
                logger.Error(message);
            }
        }

        /// <summary>
        /// 将错误信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        /// <param name="exception">记录异常信息，包含用于描述调用堆栈的直接帧的字符串。</param>
        public static void Error(object message, Exception exception)
        {
            if (logger.IsErrorEnabled)
            {
                logger.Error(message, exception);
            }
        }

        /// <summary>
        /// 将格式化异常信息写入日志文件
        /// </summary>
        /// <param name="format">格式化字符串</param>
        /// <param name="args">不定参数</param>
        public static void ErrorFormat(string format, params object[] args)
        {
            if (logger.IsErrorEnabled)
            {
                logger.ErrorFormat(format, args);
            }
        }

        /// <summary>
        /// 将严重错误写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        public static void Fatal(object message)
        {
            if (logger.IsFatalEnabled)
            {
                logger.Fatal(message);
            }
        }

        /// <summary>
        /// 将严重错误写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        /// <param name="exception">记录异常信息，包含用于描述调用堆栈的直接帧的字符串。</param>
        public static void Fatal(object message, Exception exception)
        {
            if (logger.IsFatalEnabled)
            {
                logger.Fatal(message, exception);
            }
        }

        /// <summary>
        /// 将一般信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        public static void Info(object message)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info(message);
            }
        }

        /// <summary>
        /// 将一般信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        /// <param name="exception">记录一般信息，包含用于描述调用堆栈的直接帧的字符串。</param>
        public static void Info(object message, Exception exception)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info(message, exception);
            }
        }

        /// <summary>
        /// 将一般信息写入日志文件
        /// </summary>
        /// <param name="format">格式化字符串</param>
        /// <param name="args">不定参数</param>
        public static void InfoFormat(string format, params object[] args)
        {
            if (logger.IsInfoEnabled)
            {
                logger.InfoFormat(format, args);
            }
        }

        /// <summary>
        /// 将警告信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        public static void Warn(object message)
        {
            if (logger.IsWarnEnabled)
            {
                logger.Warn(message);
            }
        }

        /// <summary>
        /// 将警告信息写入日志文件
        /// </summary>
        /// <param name="message">记录消息对象信息</param>
        /// <param name="exception">记录异常信息，包含用于描述调用堆栈的直接帧的字符串。</param>
        public static void Warn(object message, Exception exception)
        {
            if (logger.IsWarnEnabled)
            {
                logger.Warn(message, exception);
            }
        }
    }
}